import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Scanner;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jivesoftware.smack.XMPPException;

//1 12 18
//63 118 144
//11 32 42


public class LobbyPanel extends JPanel{
	private Color bg = new Color(1, 12, 18);
	private Color lb = new Color(63, 118, 144);//new Color(102, 89, 146);
	private Color taBg = new Color(11, 32, 42);
	public Output o;
	protected JTextField ta;
	protected JTextPane tp;
	protected String tps;
	protected Scanner infile;
	protected Color myColor;
	protected JButton clear;
	
	public LobbyPanel(Output arg){
		o = arg;
		tps = "";

		// border (top, left, bottom, right, color)
		
		this.setPreferredSize(new Dimension(750,600));
		this.setLayout(new BorderLayout());
		this.setBackground(bg);
		this.setBorder(BorderFactory.createCompoundBorder(BorderFactory
				.createMatteBorder(2, 2, 5, 2, Color.white), BorderFactory
				.createMatteBorder(25, 25, 35, 35, bg)));



		tp = new JTextPane();
		tp.setEditable(false);
		tp.setBackground(bg);
		tp.setForeground(Color.white);
		tp.setFont(new Font("Dialog", Font.BOLD, 13));
		tp.setBorder(BorderFactory.createCompoundBorder(BorderFactory
				.createMatteBorder(0, 18, 0, 0, bg),
				BorderFactory.createMatteBorder(0, 0, 0, 0, new Color(65, 65,
						65))));
		
		JScrollPane sp1 = new JScrollPane(tp);
		
		sp1.getVerticalScrollBar().setBackground(myColor);
		sp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		sp1.setPreferredSize(new Dimension(500, 500));
		sp1.setBorder(BorderFactory.createCompoundBorder(BorderFactory
				.createMatteBorder(3, 3, 3, 0, lb),
				BorderFactory.createMatteBorder(9, 9, 15, 0, bg)));
		sp1.setBounds(0, 0, 200, 200);

		this.add(sp1, BorderLayout.CENTER);
		
		ta = new JTextField();
		ta.setPreferredSize(new Dimension(40, 35));
		ta.setBackground(taBg);
		ta.setForeground(Color.white);
		ta.setFont(new Font("Dialog", Font.BOLD, 13));
		ta.setBorder(BorderFactory.createCompoundBorder(BorderFactory
				.createMatteBorder(2, 5, 5, 5, lb),
				BorderFactory.createMatteBorder(3, 10, 3, 3, taBg)));
		this.add(ta, BorderLayout.SOUTH);
		
		ta.addKeyListener(new AreaKeyListener());

	}
	public void addLine(String arg1, String arg2){
		tps = tps + "\n" + arg1 + ": " + arg2;
		tp.setText(tps);
		tp.setCaretPosition(tp.getDocument().getLength());
	}
	public void clearText(){
		tps = "";
		tp.setText(tps);
		tp.setCaretPosition(tp.getDocument().getLength());
	}

	private class AreaKeyListener implements KeyListener {
		public void keyTyped(KeyEvent e) {
		}
		public void keyPressed(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
				System.out.println("sending message");
				try {
					o.muc.sendMessage(ta.getText());
				} catch (XMPPException e1) {
					System.out.println("message could not be sent");
				}
				ta.setText("");
				
			}
		}
		public void keyReleased(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER)
				ta.setText("");
		}
	}

}
